<?php
namespace app\index\controller;
use think\App;
use think\Controller;
use EasyWeChat\Factory;

class Index extends Controller
{
    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $config = [
            'app_id' => env('WX_APP_ID'),
            'secret' => env('WX_APP_SECRET'),
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',
        ];
        try {
            if (is_we_chat()) {
                $app = Factory::officialAccount($config);
                $signPackage = $app->jssdk->buildConfig([
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareQZone',
                ]);
                $this->view->assign('signPackage', $signPackage);
                $this->view->assign('share_title', '美味不用等');
                $this->view->assign('share_desc', '美味不用等，全程无线连接，台面整洁美观，显档次，自助取号（POS排队机），服务员发号（平板）');
                $this->view->assign('share_link', '');
                $this->view->assign('share_img', 'http://www.xinrongchuang.cn/theme/images/download-app.jpg');
            }
        }catch (\Exception $e) {

        }
    }

    public function index()
    {
        return $this->template(__FUNCTION__);
    }
    public function about()
    {
        return $this->template(__FUNCTION__);
    }
    public function customers()
    {
        return $this->template(__FUNCTION__);
    }
    public function faq()
    {
        return $this->template(__FUNCTION__);
    }
    public function products()
    {
        return $this->template(__FUNCTION__);
    }
    private function template($template){
        $this->view->assign('func', $template);
        return $this->view->fetch($template);
    }
}